package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbRole;
import com.oig.sys.auth.vo.RoleVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbRoleDao extends JpaRepository<TbRole, Integer>, JpaSpecificationExecutor<TbRole> {

	TbRole getTbRoleById(Integer id);

	@Query("select new com.oig.sys.auth.vo.RoleVo(r.id, r.roleCode, r.roleName, r.tenantId, r.tenantCode, r.tenantName," +
			" r.createUserName,r.createTime,r.lastUpdateName,r.lastUpdateTime, r.noDelFlag) " +
			" from TbRole r " +
			" where r.id=:id")
	RoleVo getVoById(@Param("id") Integer id);


	@Query("select new com.oig.sys.auth.vo.RoleVo(r.id, r.roleCode, r.roleName, r.tenantId, r.tenantCode, r.tenantName," +
			" r.createUserName,r.createTime,r.lastUpdateName,r.lastUpdateTime, r.noDelFlag) " +
			" from TbRole r " +
			" where r.id in(:idList)")
	List<RoleVo> findAllByIdIn(@Param("idList") List<Integer> idList) ;


}
